package com.xyht.sca_s.student_manage_system.modules.album.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.album.entity.req.*;
import com.xyht.sca_s.student_manage_system.modules.album.service.SmsAlbumService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 相册主表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-07-31
 */
@RestController
@RequestMapping("/album")
@SecretBody
public class SmsAlbumController {

    @Resource
    private SmsAlbumService smsAlbumService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;


    @ApiModelProperty("新建相册")
    @PostMapping("/addAlbum")
    public ResponseResult addAlbum(@RequestBody SmsAlbumAddReq albumAddReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.addAlbum(albumAddReq,userId);
    }

    @ApiModelProperty("修改相册")
    @PostMapping("/updateAlbum")
    public ResponseResult updateAlbum(@RequestBody SmsAlbumAddReq albumAddReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.updateAlbum(albumAddReq,userId);
    }

    @ApiModelProperty("删除相册")
    @PostMapping("/deletedAlbum")
    public ResponseResult deletedAlbum(@RequestBody SmsAlbumDelReq delReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.deletedAlbum(delReq.getAlbumId(),userId);
    }

    @ApiModelProperty("查看单个相册信息")
    @GetMapping("/getAlbumEdit")
    public ResponseResult getAlbumEdit(@RequestParam(value = "albumId",required = false) String albumId){
        return smsAlbumService.getAlbumEdit(albumId);
    }

    @ApiModelProperty("权限人查看相册列表")
    @GetMapping("/getAlbumList")
    public ResponseResult getAlbumList (HttpServletRequest request,
                                        @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.getAlbumList(userId,pageSize,pageNum);
    }

    @ApiModelProperty("管理员查看相册列表")
    @GetMapping("/getAdminAlbumList")
    public ResponseResult getAdminAlbumList (@RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.getAdminAlbumList(pageSize,pageNum,userId);
    }

    @ApiModelProperty("查看单个相册图片信息")
    @GetMapping("/getAlbumId")
    public ResponseResult getAlbumId(@RequestParam(value = "albumId",required = false) String albumId,
                                     @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.getAlbumId(albumId,pageSize,pageNum,userId);
    }

    @ApiModelProperty("新增单个相册里的图片")
    @PostMapping("/addAlbumPhotos")
    public ResponseResult addAlbumPhotos(@RequestBody SmsAlbumPhotosReq addAlbumPhotosReq){
        return smsAlbumService.addAlbumPhotos(addAlbumPhotosReq);
    }

    @ApiModelProperty("删除单个相册里的图片")
    @PostMapping("/deletedPhotoId")
    public ResponseResult deletedAlbumPhotos(@RequestBody SmsAlbumPhotoDelReq photoDelReq){
        return smsAlbumService.deletedAlbumPhotos(photoDelReq);
    }

    @ApiModelProperty("查看更多的照片")
    @GetMapping("getAllPhotoByTime")
    public ResponseResult getAllPhotoByTime(@RequestParam(value = "albumId",required = false) String albumId,
                                            @RequestParam(value = "photoTime", required = false) Date photoTime){
        return smsAlbumService.getAllPhotoByTime(albumId,photoTime);
    }

    @ApiModelProperty("新增浏览量")
    @PostMapping("/addView")
    public ResponseResult addAlbumView(@RequestBody SmsAlbumViewAddReq albumViewAddReq,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.addAlbumView(albumViewAddReq,userId);
    }

    @ApiModelProperty("点赞")
    @PostMapping("/like")
    public ResponseResult likeAlbum(@RequestBody SmsAlbumViewAddReq albumViewAddReq,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAlbumService.likeAlbum(albumViewAddReq,userId);
    }

}

